package arabicScrabble;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.*;

public class Letter extends JButton {
	char symbol;
	int score;
	Square square;
	int i;
	int j;
	BufferedImage img;
	boolean blank=false;
	boolean blankF=false;
	Letter(char symbol, int score) {
		this(symbol, score, null);
	}

	Letter(char symbol, int score, String imagePath) {
		super();
		try {

			img = ImageIO.read(new File(imagePath));
		} catch (IOException e) {
			System.out.println("This Image Doesn't Exist: \n\t\t" + imagePath);
		}
		this.symbol = symbol;
		this.score = score;
		if(symbol=='.'){
			blank=true;
			blankF=true;
		}
	}

	public int getI() {
		return i;
	}

	public int getJ() {
		return j;
	}

	public void setXi(int i) {
		this.i = i;
	}

	public void setYj(int j) {
		this.j = j;
	}

	public Letter() {
		// TODO Auto-generated constructor stub
	}

	public int getScore() {
		return score;
	}

	public Square getSquare() {
		return square;
	}

	public void setSquare(Square s) {
		square = s;
	}

	@Override
	public void paint(Graphics g) {
		if (img == null) {
			super.paint(g);
		} else if (this.isEnabled()) {
			this.setIcon(getResizedIcon());
			super.paint(g);
		} else {
			g.drawImage(img, 0, 0, this.getWidth(),this.getHeight(), null);
		}
	}

	public Icon getResizedIcon() {
		BufferedImage resizedImage = new BufferedImage(40,
				40, img.getType());

		Graphics2D g2d = resizedImage.createGraphics();
		g2d.drawImage(img, 0, 0, 40, 40, null);
		g2d.dispose();
		if (this.getIcon() == null) {
			return new ImageIcon(resizedImage);
		} else {
			((ImageIcon) this.getIcon()).setImage(resizedImage);
			return this.getIcon();
		}
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return "[Symbol: " + this.symbol + "square: " + square + "]";
	}
}
